#include <iostream>
using namespace std;
const int N = 2e3 + 7;
int n;
int ans = 0;
int cnt[N];

void solve()
{
  cin >> n;
  string op;
  while(cin >> op)
  {
    if(op == "add")
    {
      int x;
      cin >> x;
      cnt[0]++;
    }
    else if(op == "sync")
    {
      int x;
      cin >> x;
      if(cnt[x] < cnt[0])cnt[x]++;
    }
    else
    {
      int ans = 1e5;
      for(int i = 1;i < n;i++)
      {
        ans = min(ans,cnt[i]);
      }
      cout << ans << endl;
    }
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}